#ifndef _MAINRUNIMPL_H_
#define _MAINRUNIMPL_H_

#include "stdafx.h"
#include "objectrun.h"
#include "plugins.h"

class CMainRunImpl : public IMainRun, public CUnknownImp
{
public:
    CMainRunImpl(void);
    virtual ~CMainRunImpl(void);

    BEGIN_STDCOM_MAP
    STDCOM_INTERFACE_ENTRY_UNKNOWN_(IMainRun)
    STDCOM_INTERFACE_ENTRY(IMainRun)
    END_STDCOM_MAP

public:
    // IMainRun
    std_method(CreateObject)(REFCLSID rid, IBase** pIObjectRun, SafePStringConstPtr path, SafeStringConstPtr code);
    std_method_(int, IsObjectExist)(REFCLSID rid);
    std_method(GetObjectRun)(REFCLSID rid, IBase** pIObjectRun);
    std_method(GetObject)(REFCLSID rid, REFCLSID clsid, REFCLSID iid, IBase** ppunk);
    std_method(FreeObject)(REFCLSID id, UINT exit);
    std_method(Free)(UINT exit);
    std_method(SendMsg)(REFCLSID rid, REFCLSID gn, REFCLSID sn, REFCLSID tn, UINT msg, IBase* inmsg, IBase** outmsg);
    std_method(SendBroadcastMsg)(REFCLSID gn, REFCLSID sn, REFCLSID tn, UINT msg, IBase* inmsg);

private:
    typedef struct ObjectRunItem {
        ObjectRunPtr m_ptr;
    } * pObjectRunItemPtr;

    typedef std::map<CLSID, ObjectRunItem, clscmp> ObjectStruct;
    typedef ObjectStruct::iterator ObjectStructIterator;
    ObjectStruct m_obj;
    CAutoLock m_lock;
};

#endif
